<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Start of file departements.php */
/* Location: ./cashflow/models/budgets.php */
class Budgets extends CI_Model {
    
	function __construct(){
        parent::__construct(); /** Call the Model constructor */
    }
	
	function getDataBudget($all_header=''){
		$this->db->where('Kelompok','BUDGET');
        if($all_header)
            $this->db->where("(Jenis='H1' OR Jenis='H2' OR Jenis='H3' OR Jenis='H4')");
        else     
            $this->db->where("(Jenis='H1' OR Jenis='H2')"); 
        $Q=$this->db->get('budget');
		if ($Q->num_rows() > 0):
			foreach ($Q->result_array() as $row):
                $data['']             = 'All';
				$data[$row['NoUrut']] = $row['Ikhtisar'];
			endforeach;
		endif;
        $Q->free_result();
		return $data;   
	}
    
    function getAllAccount(){
        $this->db->where('Kelompok','BUDGET');
        //$this->db->where("(Jenis='H1' OR Jenis='H2' OR Jenis='H3' OR Jenis='H4' OR Jenis='T1' OR Jenis='T2' OR Jenis='T3' OR Jenis='T4' OR Jenis='D' )");
        $this->db->order_by('NoUrut','ASC');
        $Q=$this->db->get('budget');
        return $Q->result_array();
    }
    
    function getBudgetAccount($no_urut=''){
        if(($no_urut)):
            if(($no_urut!='-') )
                $this->db->where('LEFT(NoUrut,3)',$no_urut);
        endif;        
        $this->db->where('Kelompok','BUDGET');
        $this->db->where_not_in('MataAnggaran','');
        $this->db->order_by('NoUrut','ASC');
        $Q=$this->db->get('budget');
        return $Q->result_array();
    }
    
    function getBudgetFooter($no_urut){
        if($no_urut):
                $this->db->where('LEFT(NoUrut,3)',$no_urut);
        endif;     
        $this->db->where("(Jenis='T1' OR Jenis='T2' OR Jenis='T3' OR Jenis='T4' )");
        $this->db->order_by('NoUrut','ASC');
        $Q=$this->db->get('budget',1);
        return $Q->row_array();
    }
    
    function getBudgetFooter2(){  
        $this->db->where("(Jenis='TH')");
        $this->db->where('Kelompok','BUDGET');
        $this->db->order_by('NoUrut','ASC');
        $Q=$this->db->get('budget',1);
        return $Q->row_array();
    }
    
    function getHeaderAccount($no_urut=''){
        if($no_urut)
            $this->db->where('NoUrut',$no_urut);
        $this->db->where('Kelompok','BUDGET');
        $this->db->where("(Jenis='H1' OR Jenis='H2' OR Jenis='H3' OR Jenis='H4') ");
        $this->db->order_by('NoUrut','ASC');
        $Q=$this->db->get('budget');
        return $Q->result_array();
    }
    
    function getBudgetSet($year,$month,$acc,$dep='',$per_month='',$no='',$no_urut=''){
        $this->db->select('SUM(Anggaran) as tAnggaran,Anggaran,Realisasi,(Anggaran+Realisasi) as AR');  
        if($no_urut):
            $this->db->join('budget','budget.MataAnggaran=budgetset.MataAnggaran');
            $this->db->where('LEFT(NoUrut,'.$no.')',$no_urut);
        endif;          
        $this->db->where('budgetset.Tahun',$year);
        if($acc)
            $this->db->where('budgetset.MataAnggaran',$acc);
        $this->db->where('budgetset.DeptID',$dep);    
        $Q=$this->db->get('budgetset');
        $val = $Q->row_array();
        return $val;
    }
}
    